package com.xiaoxin.admin.controller;

import com.xiaoxin.admin.service.ManagerService;
import com.xiaoxin.model.domain.UserInfo;
import com.xiaoxin.model.vo.MovementsVo2;
import com.xiaoxin.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiaoxiaode
 * @date 2021/9/14 20:33
 **/
@RestController
@RequestMapping("/manage")
public class ManagerController {

    @Autowired
    private ManagerService managerService;

    /*
     * 查询用户列表
     * */
    @GetMapping("/users")
    public ResponseEntity getUsers(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult result = managerService.getUsers(page, pagesize);
        return ResponseEntity.ok(result);
    }

    /*
     * 根据id查询
     * */
    @GetMapping("/users/{userId}")
    public ResponseEntity findByUserId(@PathVariable("userId") Long userId) {
        UserInfo info = managerService.findByUserId(userId);
        return ResponseEntity.ok(info);
    }

    /*
     *根据id查询用户视频
     * */
    @GetMapping("/videos")
    public ResponseEntity userVideos(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pagesize,
                                     Long uid) {
        PageResult result = managerService.getUserVideos(page, pagesize, uid);
        return ResponseEntity.ok(result);
    }

    /*
    *查询用户动态列表
    * */
    @GetMapping("/messages")
    public ResponseEntity getMessages(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize,
                                      Long uid,Integer state){
        PageResult result=managerService.getMessages(page,pagesize,uid,state);
        return ResponseEntity.ok(result);
    }


    /*
     * 查询动态详情
     * */
    @GetMapping("/messages/{id}")
    public ResponseEntity getMovement(@PathVariable("id") Long  movementId) {
        MovementsVo2 vo = managerService.getMovement(movementId);
        return ResponseEntity.ok(vo);
    }

}
